<!--特殊操作页面-->
<template>
  <div>
    <!--特殊操作按钮-->
    <div>
      <!--特殊出库申请按钮-->
      <el-button type="primary" v-if="roleType === '2' || roleType === '3'" @click="onSpecialOutStock()">特殊出库申请
      </el-button>
      <!--特殊维修工单关单申请按钮-->
      <el-button type="primary" v-if="roleType === '2' || roleType === '3'" @click="onSpecialCloseOrder()">特殊维修工单关单申请
      </el-button>
    </div>
    <!--条件查询-->
    <div style="margin-top: 20px">
      <el-form :inline="true">
        <!--总部管理员账号时显示省份查询-->
        <el-form-item v-if="roleType === '1'">
          <el-select v-model="specialOperationSearchDto.provinceCode" clearable placeholder="请选择省份">
            <el-option
              v-for="item in allSelectProvince"
              :key="item.code"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <!--申请原因模糊查询-->
        <el-form-item>
          <el-input v-model="specialOperationSearchDto.cause" clearable placeholder="请填写申请原因关键字">
          </el-input>
        </el-form-item>
        <!--申请时间段查询-->
        <el-form-item>
          <el-date-picker
            v-model="specialOperationSearchDto.proposeTime" clearable
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="申请时间段开始日期"
            end-placeholder="申请时间段结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="specialOperationSearch()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--历史申请工单信息tabs-->
    <div>
      <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="待审核" name="operation">
          <custom-table
            :columns="operationColumns"
            :data="operationList"
            :tableLoadingFlag="tableLoadingFlag"
            :operationColumn="operationColumn"
            :pagination="pagination">
          </custom-table>
        </el-tab-pane>
        <el-tab-pane label="已审核" name="alreadyOperation">
          <custom-table
            :columns="operationColumns"
            :data="alreadyOperationList"
            :tableLoadingFlag="tableLoadingFlag"
            :operationColumn="operationColumn"
            :pagination="alreadyPagination">
          </custom-table>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!--特殊出库申请单模态框-->
    <div>
      <el-dialog title="特殊出库申请单" :visible.sync="specialOutStockVisible" center width="50%"
                 :close-on-click-modal="false" :show-close="false">
        <el-form class="form-horizontal" :model="specialOutStockDto" label-width="120px"
                 ref="specialOutStockForm" :rules="specialOutStockRules">
          <!--申请人 默认为当前操作人-->
          <el-form-item label="申请人" prop="proposer">
            <el-input :disabled="true" v-model="specialOutStockDto.outStockProposer"></el-input>
          </el-form-item>
          <!--申请时间 默认当前时间-->
          <el-form-item label="申请时间" prop="proposeTime">
            <el-input :disabled="true" v-model="specialOutStockDto.outStockProposeTime"></el-input>
          </el-form-item>
          <!--申请出库设备的库来源-->
          <el-form-item label="设备库源" prop="stockType">
            <el-select v-model="specialOutStockDto.stockType" placeholder="请选择设备库源" clearable>
              <el-option v-for="stockSource in stockTypeOption"
                         :key="stockSource.value"
                         :label="stockSource.label"
                         :value="stockSource.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!--申请出库设备数量-->
          <el-form-item label="设备数量" prop="outStockDeviceCount">
            <el-input-number v-model="specialOutStockDto.outStockDeviceCount" :min="1">
            </el-input-number>
          </el-form-item>
          <!--申请出库导入模板下载-->
          <el-form-item label="下载模板" prop="download">
              <a href="/static/特殊出库导入模板.xlsx" download="特殊出库导入模板.xlsx">
                特殊出库申请导入模板下载
              </a>
          </el-form-item>
          <!--出库申请设备信息导入-->
          <el-form-item label="文件导入" prop="upload"></el-form-item>
            <div>
              <el-form label-width="80px" ref="uploadForm" :inline="true">
                <el-form-item style="padding-left: 120px">
                  <el-upload
                    class="upload-demo"
                    :action="uploadUrl"
                    :headers="myHeaders"
                    name="file"
                    :on-error="uploadError"
                    :on-success="uploadSuccess"
                    :before-upload="beforeAvatarUpload"
                    multiple
                    drag
                    :limit="1"
                    :file-list="fileList">
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em><br/>只能上传xlsx文件，且不超过10M</div>
                  </el-upload>
                </el-form-item>
              </el-form>
            </div>
          <!--显示导入中错误的数据-->
          <div style="margin-bottom: 20px" v-if="hideTable">
            <div>
              <h3 style="text-align: center">文件错误信息提示表格</h3>
            </div>
            <custom-table
              :data="wrongDataList"
              :columns="uploadErrorColumns"
              :maxHeight="200">
            </custom-table>
          </div>
          <!--出库说明-->
          <el-form-item label="出库说明" prop="outStockCause">
            <el-input v-model="specialOutStockDto.outStockCause" placeholder="请填写出库说明"></el-input>
          </el-form-item>
          <el-form-item>
            <el-row>
              <el-col :span="16">
                <el-button @click="outStockSubmit()" type="primary">确认</el-button>
              </el-col>
              <el-col :span="8">
                <el-button @click="outStockCancer()" type="primary">取消</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
    <!--特殊维修工单关单申请模态框-->
    <el-dialog title="特殊维修工单关单申请单" :visible.sync="specialCloseOrderVisible" center width="50%"
               :close-on-click-modal="false" :show-close="false">
      <el-form class="form-horizontal" :model="specialCloseOrderDto" label-width="120px"
               ref="specialCloseOrderForm" :rules="specialCloseOrderRules">
        <!--申请人 默认为当前操作人-->
        <el-form-item label="申请人" prop="proposer">
          <el-input :disabled="true" v-model="specialCloseOrderDto.closeOrderProposer"></el-input>
        </el-form-item>
        <!--申请时间 默认当前时间-->
        <el-form-item label="申请时间" prop="proposeTime">
          <el-input :disabled="true" v-model="specialCloseOrderDto.closeOrderProposeTime"></el-input>
        </el-form-item>
        <!--申请特殊维修工单关单导入模板下载-->
        <el-form-item label="下载模板" prop="download">
          <a href="/static/特殊维修工单关单导入模板.xlsx" download="特殊维修工单关单导入模板.xlsx">
            特殊维修工单关单申请导入模板下载
          </a>
        </el-form-item>
        <!--关单申请设备信息导入-->
        <el-form-item label="文件导入" prop="upload"></el-form-item>
        <div>
          <el-form label-width="80px" ref="uploadForm" :inline="true">
            <el-form-item style="padding-left: 120px">
              <el-upload
                class="upload-demo"
                :action="uploadUrl"
                :headers="myHeaders"
                name="file"
                :on-error="uploadError"
                :on-success="uploadSuccess"
                :before-upload="beforeAvatarUpload"
                multiple
                drag
                :limit="1"
                :file-list="fileList">
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em><br/>只能上传xlsx文件，且不超过10M</div>
              </el-upload>
            </el-form-item>
          </el-form>
        </div>
        <!--显示导入中错误的数据-->
        <div style="margin-bottom: 20px" v-if="hideTable">
          <div>
            <h3 style="text-align: center">文件错误信息提示表格</h3>
          </div>
          <custom-table
            :data="wrongDataList"
            :columns="uploadErrorColumns"
            :maxHeight="200">
          </custom-table>
        </div>
        <!--关单说明-->
        <el-form-item label="关单说明" prop="closeOrderCause">
          <el-input v-model="specialCloseOrderDto.closeOrderCause" placeholder="请填写关单原因说明"></el-input>
        </el-form-item>
        <el-form-item>
          <el-row>
            <el-col :span="16">
              <el-button @click="closeOrderSubmit()" type="primary">确认</el-button>
            </el-col>
            <el-col :span="8">
              <el-button @click="closeOrderCancer()" type="primary">取消</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--特殊操作审核模态框-->
    <div>
      <el-dialog :title=auditTitle :visible.sync="specialOperationAuditVisible" center width="50%"
                 :close-on-click-modal="false">
        <el-form :model="specialOperationAuditDto" :rules="specialOperationAuditRules" label-width="60px"
                 ref="specialOperationAuditForm">
          <el-form-item label="审核" prop="auditResult">
            <el-radio-group v-model.number="specialOperationAuditDto.auditResult">
              <el-radio-button label="1">同意</el-radio-button>
              <el-radio-button label="2">不同意</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="原因" prop="cause">
            <el-input v-model.trim="specialOperationAuditDto.cause" placeholder="请输入原因"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer">
          <el-button @click="operationAuditCancel()">取消</el-button>
          <el-button type="primary" @click="operationAuditSubmit()">确定</el-button>
        </div>
      </el-dialog>
    </div>
    <!--特殊操作申请记录详情模态框-->
    <div>
      <el-dialog title="设备详情" :visible.sync="specialDetailVisible"
                 :close-on-click-modal="false">
        <custom-table
          :data="detailList"
          :columns="detailColumns"
          :tableLoadingFlag="tableLoadingFlag"
          :pagination="detailPagination">
        </custom-table>
        <div slot="footer">
          <el-button type="primary" @click="detailCancel()">取消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
  import {parseTime} from '@/utils'
  import {baseInfo} from '@/utils/fetch'
  import store from '@/store'
  import CustomTable from '@/components/table/CustomTable'
  import {getName, getRoleType, getOfficeId, getOutsourceId, getProvinceCode, getCityCode, getUserId} from '@/utils/token'
  import {apiSpecialOperation, apiGetSpecialOperationList, apiSpecialOperationAudit, apiGetSpecialDetailList} from '@/api/stock/index'
  import {apiGetAllAuditList} from '@/api/config/audit'
  import {apiGetCity} from '@/api/dictionary'

  export default{
    components: {
      CustomTable
    },
    created () {
      this.initInfo()
      this.initOperation()
      this.initSelectProvince()
      this.getSpecialOperationList()
    },
    data () {
      return {
        // 账户角色类型
        roleType: '',
        // 网点id
        pointId: '',
        // 网点类型
        pointType: '',
        // 省份code
        provinceCode: '',
        // 城市code
        cityCode: '',
        // 账号id
        userId: '',
        // 账号姓名
        userName: '',
        // 审核模态框title
        auditTitle: '',
        // tabs名称变量
        activeName: 'operation',
        // 当前tab
        tab: 0, // 0为待审核tab，1为已审核tab
        // 文件上传路径
        uploadUrl: baseInfo() + '/api/v1/upload',
        // 文件上传头
        myHeaders: {'access_token': store.getters.token},
        // 上传文件显示
        fileList: [],
        flagList: [],
        // 上传信息错误
        wrongDataList: [],
        // 待审核历史特殊操作申请单信息list
        operationList: [],
        // 已审核历史特殊操作申请单信息list
        alreadyOperationList: [],
        // 特殊操作申请记录详情list
        detailList: [],
        // 所有省份
        allSelectProvince: [],
        // table加载动画
        tableLoadingFlag: false,
        // 上传信息错误table显示标志量
        hideTable: false,
        // 特殊出库申请单模态框visible标志量
        specialOutStockVisible: false,
        // 特殊特殊维修工单关单申请单模态框visible标志量
        specialCloseOrderVisible: false,
        // 特殊操作审核模态框标志量
        specialOperationAuditVisible: false,
        // 特殊操作记录详情标志量
        specialDetailVisible: false,
        // 待审核分页组件
        pagination: this.getData(this.getSpecialOperationList),
        // 已审核分页组件
        alreadyPagination: this.getData(this.getSpecialOperationList),
        // 详情页面分页功能
        detailPagination: this.getData(this.getOperationDetail),
        // 特殊出库申请表单数据
        specialOutStockDto: {
          outStockProposer: getName(), // 出库申请人
          outStockProposeTime: parseTime(new Date().getTime()), // 出库申请时间
          stockType: '', // 出库设备库源类型
          outStockDeviceCount: '', // 申请出库设备的数量
          outStockCause: '', // 出库说明
          filePath: '' // 上传文件的访问路径
        },
        // 特殊维修工单关单申请表单数据
        specialCloseOrderDto: {
          closeOrderProposer: getName(), // 关单申请人
          closeOrderProposeTime: parseTime(new Date().getTime()), // 关单申请时间
          closeOrderCause: '', // 关单原因说明
          filePath: '' // 上传文件的访问路径
        },
        // 特殊操作申请审核表单数据
        specialOperationAuditDto: {
          auditorId: '', // 审核人id
          auditorName: '', // 审核人姓名
          auditResult: 2, // 审核结果，默认未不通过
          applicationId: '', // 特殊操作申请单号
          operationType: '', // 特殊操作类型
          cause: '', // 审核原因
          auditTime: parseTime(new Date().getTime()) // 审核日期
        },
        // 特殊操作申请条件查询表单
        specialOperationSearchDto: {
          provinceCode: '', // 省份查询
          cause: '', // 出库或关单申请原因模糊查询
          proposeTime: [] // 申请时间段查询
        },
        // 设备库源选项
        stockTypeOption: [
          {
            value: 1,
            label: '良品库'
          },
          {
            value: 2,
            label: '不良品库'
          },
          {
            value: 3,
            label: '报废库'
          }
        ],
        // 上传信息错误column
        uploadErrorColumns: [
          {label: '错误行号', name: 'wrongRowNO', width: '100', align: 'center'},
          {label: '错误原因', name: 'reason', width: '180', align: 'center'},
          {label: '型号', name: 'model', width: '164', align: 'center'},
          {label: 'SN号', name: 'ystsn', width: '180', align: 'center'}
        ],
        // 历史申请工单信息column
        operationColumns: [
          {label: '省份', name: 'provinceName', width: '100', align: 'center'},
          {label: '城市', name: 'cityName', width: '100', align: 'center'},
          {label: '操作类型', name: 'operationType', width: '150', align: 'center', formatter: this.formatOperationType},
          {label: '申请人', name: 'proposerName', width: '100', align: 'center'},
          {label: '申请时间', name: 'proposeTime', width: '180', align: 'center', formatter: this.formatTimestamp},
          {label: '申请数量', name: 'num', width: '100', align: 'center'},
          {label: '原因说明', name: 'cause', width: '100', align: 'center'},
          {label: '审核人', name: 'auditor', width: '100', align: 'center'},
          {label: '审核日期', name: 'auditTime', width: '180', align: 'center', formatter: this.formatTimestamp},
          {label: '审核状态', name: 'auditStatus', width: '100', align: 'center', formatter: this.formatOperationAuditStatus}
        ],
        // 申请记录详情column
        detailColumns: [
          {label: '型号', name: 'model', width: '150', align: 'center'},
          {label: 'YSTSN', name: 'ystsn', align: 'center'}
        ],
        // 操作column
        operationColumn: {
          width: '120',
          operations: [
            {name: '详情', callback: this.getOperationDetail}
          ]
        },
        // 特殊出库申请单数据验证
        specialOutStockRules: {
          stockType: [
            {required: true, message: '请选择要出库设备的来源库', trigger: 'change'}
          ],
          outStockCause: [
            {required: true, message: '请输入特殊出库说明', trigger: 'blur'}
          ]
        },
        // 特殊关单申请单数据验证
        specialCloseOrderRules: {
          closeOrderCause: [
            {required: true, message: '请输入特殊关单原因说明', trigger: 'blur'}
          ]
        },
        // 特殊操作申请审核表单数据验证
        specialOperationAuditRules: {
          cause: [
            {
              validator: (rule, value, callback) => {
                if (this.specialOperationAuditDto.auditResult === 2 && value === '') {
                  callback(new Error('请输入不同意原因'))
                } else {
                  callback()
                }
              },
              trigger: 'blur'
            },
            {max: 255, message: '长度不得超过255字符', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      // 账号姓名，账户类型，网点信息，省市初始化
      initInfo () {
        this.userId = getUserId()
        this.userName = getName()
        this.roleType = getRoleType()
        if (this.roleType === '2') {
          this.pointId = getOfficeId()
          this.pointType = 0
        } else if (this.roleType === '3') {
          this.pointId = getOutsourceId()
          this.pointType = 1
        } else {
          this.pointId = ''
          this.pointType = ''
        }
        this.provinceCode = getProvinceCode()
        this.cityCode = getCityCode()
      },
      // 页面table中操作一栏的初始化
      initOperation () {
        // 获取特殊操作申请审核人信息
        apiGetAllAuditList().then(response => {
          let auditor = []
          for (let i = 0; i < response.data.length; i++) {
            if (response.data[i].auditModule === 4) {
              auditor = response.data[i]
            }
          }
          // 当角色为总部账号且为特殊操作审核人时
          if (this.roleType === '1' && this.userId === auditor.approverId.toString()) {
            this.operationColumn = {
              width: '80',
              operations: [
                {name: '审核', callback: this.specialOperationAudit, page: 'specialOperationAudit'},
                {name: '详情', callback: this.getOperationDetail}
              ]
            }
          }
        })
      },
      // 初始化省份查询选择框
      initSelectProvince () {
        apiGetCity().then(response => {
          this.allSelectProvince = response.data
        })
      },
      // 格式化接受日期时间戳
      formatTimestamp (row, column, cellValue) {
        return parseTime(cellValue, '{y}-{m}-{d} {hh}:{ii}:{ss}')
      },
      // 格式化特殊操作类型状态
      formatOperationType (row, column, cellValue) {
        if (cellValue === 1) {
          return '特殊出库'
        } else if (cellValue === 2) {
          return '特殊维修工单关单'
        }
      },
      // 格式化审核状态
      formatOperationAuditStatus (row, column, cellValue) {
        if (cellValue === null) {
          return '待审核'
        } else if (cellValue === '1') {
          return '审核通过'
        } else {
          return '审核不通过'
        }
      },
      // 获取历史申请单信息详情
      getOperationDetail (row) {
        this.detailList = []
        if (row.applicationId) {
          this.applicationId = row.applicationId
        } else {
          row.applicationId = this.applicationId
        }
        this.tableLoadingFlag = true
        let listQuery = {
          pageNumber: this.detailPagination.currentPage,
          pageSize: this.detailPagination.pageSize,
          applicationId: row.applicationId
        }
        apiGetSpecialDetailList(listQuery).then(response => {
          this.detailList = response.data
          this.detailPagination.totalRecords = response.totalRecords
          this.specialDetailVisible = true
          this.tableLoadingFlag = false
        }).catch(() => {
          this.tableLoadingFlag = false
        })
      },
      // 特殊出库申请按钮，弹出模态框
      onSpecialOutStock () {
        if (this.$refs['specialOutStockForm']) {
          this.specialOutStockDto = {
            outStockProposer: getName(),
            outStockProposeTime: parseTime(new Date().getTime()),
            stockType: '',
            outStockDeviceCount: 0,
            outStockCause: ''
          }
        }
        this.specialOutStockVisible = true
      },
      // 特殊关单申请按钮，弹出关单模态框
      onSpecialCloseOrder () {
        if (this.$refs['specialCloseOrderForm']) {
          this.specialCloseOrderDto = {
            closeOrderProposer: getName(),
            closeOrderProposeTime: parseTime(new Date().getTime()),
            closeOrderCause: ''
          }
        }
        this.specialCloseOrderVisible = true
      },
      // 上传成功后的回调
      uploadSuccess (response, file, fileList) {
        this.$message({
          showClose: true,
          message: '上传文件成功',
          type: 'success'
        })
        if (this.specialOutStockVisible) {
          this.specialOutStockDto.filePath = response.data
        } else if (this.specialCloseOrderVisible) {
          this.specialCloseOrderDto.filePath = response.data
        }
        this.flagList = fileList
      },
      // 上传失败回调
      uploadError () {
        this.$message({
          showClose: true,
          message: '上传失败，请重试！'
        })
      },
      // 上传文件格式与大小限定
      beforeAvatarUpload (file) {
        const extension = file.name.split('.')[1] === 'xlsx'
        const isLt2M = file.size / 1024 / 1024 < 10
        if (!extension) {
          this.$message({
            showClose: true,
            message: '上传模板只能是 xlsx 格式!'
          })
        }
        if (!isLt2M) {
          this.$message({
            showClose: true,
            message: '上传模板大小不能超过 10MB!'
          })
        }
      },
      // 确定提交特殊出库申请按钮
      outStockSubmit () {
        this.$refs['specialOutStockForm'].validate((valid) => {
          if (valid) {
            if (this.flagList !== undefined && this.flagList.length > 0) {
              let listQuery = {
                pointId: this.pointId,
                pointType: this.pointType,
                proposerId: this.userId,
                proposerName: this.specialOutStockDto.outStockProposer,
                operationType: 1, // 特殊出库操作
                stockType: this.specialOutStockDto.stockType,
                filePath: this.specialOutStockDto.filePath,
                num: this.specialOutStockDto.outStockDeviceCount,
                provinceCode: this.provinceCode,
                cityCode: this.cityCode,
                cause: this.specialOutStockDto.outStockCause
              }
              apiSpecialOperation(listQuery).then(response => {
                if (response.status === 'success') {
                  this.$message({
                    showClose: true,
                    message: '提交特殊出库申请成功',
                    type: 'success'
                  })
                  let listquery = {}
                  this.getSpecialOperationList(listquery)
                  this.outStockCancer()
                } else if (response.status === 'error') {
                  if (response.data[0].wrongRowNO) {
                    this.$message({
                      showClose: true,
                      message: '文件有误，请查看错误信息提示表格',
                      type: 'error'
                    })
                    this.wrongDataList = response.data
                    this.hideTable = true
                  }
                }
              })
              this.wrongDataList = []
              this.fileList = []
              this.hideTable = false
              this.$refs['uploadForm'].resetFields()
            } else {
              this.$message({
                showClose: true,
                message: '未导入文件',
                type: 'error'
              })
              return
            }
          } else {
            return false
          }
        })
      },
      // 取消特殊出库申请
      outStockCancer () {
        this.specialOutStockVisible = false
        this.wrongDataList = []
        this.fileList = []
        this.hideTable = false
        this.flagList = []
        this.$refs['uploadForm'].resetFields()
        if (this.$refs['specialOutStockForm'] !== undefined) {
          this.$refs['specialOutStockForm'].resetFields()
        }
      },
      // 确定提交特殊关单申请
      closeOrderSubmit () {
        this.$refs['specialCloseOrderForm'].validate((valid) => {
          if (valid) {
            if (this.flagList !== undefined && this.flagList.length > 0) {
              let listQuery = {
                pointId: this.pointId,
                pointType: this.pointType,
                proposerId: this.userId,
                proposerName: this.specialCloseOrderDto.closeOrderProposer,
                operationType: 2, // 特殊关单操作
                filePath: this.specialCloseOrderDto.filePath,
                provinceCode: this.provinceCode,
                cityCode: this.cityCode,
                num: 1,
                stockType: 0,
                cause: this.specialCloseOrderDto.closeOrderCause
              }
              apiSpecialOperation(listQuery).then(response => {
                if (response.status === 'success') {
                  this.$message({
                    showClose: true,
                    message: '提交特殊维修工单关单申请成功',
                    type: 'success'
                  })
                  let listquery = {}
                  this.getSpecialOperationList(listquery)
                  this.closeOrderCancer()
                } else if (response.status === 'error') {
                  console.log(1)
                  if (response.data[0].wrongRowNO) {
                    console.log(2)
                    this.$message({
                      showClose: true,
                      message: '文件有误，请查看错误信息提示表格',
                      type: 'error'
                    })
                    this.wrongDataList = response.data
                    this.hideTable = true
                  }
                }
              })
              this.wrongDataList = []
              this.fileList = []
              this.hideTable = false
              this.$refs['uploadForm'].resetFields()
            } else {
              this.$message({
                showClose: true,
                message: '未导入文件',
                type: 'error'
              })
              return
            }
          } else {
            return false
          }
        })
      },
      // 取消特殊关单申请
      closeOrderCancer () {
        this.specialCloseOrderVisible = false
        this.wrongDataList = []
        this.fileList = []
        this.hideTable = false
        this.flagList = []
        this.$refs['uploadForm'].resetFields()
        if (this.$refs['specialCloseOrderForm'] !== undefined) {
          this.$refs['specialCloseOrderForm'].resetFields()
        }
      },
      // 关闭详情模态框
      detailCancel () {
        this.specialDetailVisible = false
        this.detailPagination.currentPage = 1
        this.detailPagination.pageSize = 10
      },
      // 切换tabs事件
      handleClick () {
        if (this.activeName === 'operation') {
          this.tab = 0
        } else if (this.activeName === 'alreadyOperation') {
          this.tab = 1
        }
        this.getSpecialOperationList()
      },
      // 获取特殊操作申请历史工单信息
      getSpecialOperationList () {
        let listQuery = {
          pageNumber: this.pagination.currentPage,
          pageSize: this.pagination.pageSize,
          provinceCode: '',
          cause: '',
          pointId: this.pointId,
          pointType: this.pointType,
          proposeBeginTime: '',
          proposeEndTime: '',
          tab: this.tab
        }
        if (this.specialOperationSearchDto.provinceCode !== undefined) {
          listQuery.provinceCode = this.specialOperationSearchDto.provinceCode
        }
        if (this.specialOperationSearchDto.cause !== undefined) {
          listQuery.cause = this.specialOperationSearchDto.cause
        }
        if (this.specialOperationSearchDto.proposeTime !== undefined && this.specialOperationSearchDto.proposeTime !== null) {
          listQuery.proposeBeginTime = this.specialOperationSearchDto.proposeTime[0]
          listQuery.proposeEndTime = this.specialOperationSearchDto.proposeTime[1]
        }
        this.tableLoadingFlag = true
        if (this.tab === 0) {
          listQuery.pageSize = this.pagination.pageSize
          listQuery.pageNumber = this.pagination.currentPage
          apiGetSpecialOperationList(listQuery).then(response => {
            this.operationList = response.data
            this.pagination.totalRecords = response.totalRecords
            this.tableLoadingFlag = false
          }).catch(() => {
            this.$message({
              showClose: true,
              message: '获取待审核特殊操作申请历史工单信息失败',
              type: 'error'
            })
            this.tableLoadingFlag = false
          })
        } else if (this.tab === 1) {
          listQuery.pageSize = this.alreadyPagination.pageSize
          listQuery.pageNumber = this.alreadyPagination.currentPage
          apiGetSpecialOperationList(listQuery).then(response => {
            this.alreadyOperationList = response.data
            this.alreadyPagination.totalRecords = response.totalRecords
            this.tableLoadingFlag = false
          }).catch(() => {
            this.$message({
              showClose: true,
              message: '获取已审核特殊操作申请历史工单信息失败',
              type: 'error'
            })
            this.tableLoadingFlag = false
          })
        }
      },
      // 特殊操作工单信息条件查询
      specialOperationSearch () {
        if (this.tab === 0) {
          this.pagination.currentPage = 1
          this.pagination.pageSize = 10
        } else if (this.tab === 1) {
          this.alreadyPagination.currentPage = 1
          this.alreadyPagination.pageSize = 10
        }
        this.getSpecialOperationList()
      },
      // 特殊操作审核
      specialOperationAudit (row) {
        this.specialOperationAuditDto.applicationId = row.applicationId
        this.specialOperationAuditDto.auditorName = this.userName
        this.specialOperationAuditDto.auditorId = this.userId
        this.specialOperationAuditDto.operationType = row.operationType
        if (this.specialOperationAuditDto.operationType === 1) {
          this.auditTitle = '特殊出库审核'
        } else if (this.specialOperationAuditDto.operationType === 2) {
          this.auditTitle = '特殊维修工单关单审核'
        }
        this.specialOperationAuditVisible = true
      },
      // 特殊操作审核模态框中取消按钮事件
      operationAuditCancel () {
        this.specialOperationAuditVisible = false
        this.$refs['specialOperationAuditForm'].resetFields()
      },
      // 特殊操作审核模态框中确认按钮事件
      operationAuditSubmit () {
        this.$refs['specialOperationAuditForm'].validate((valid) => {
          if (valid) {
            // 审核接口
            apiSpecialOperationAudit(this.specialOperationAuditDto).then(() => {
              this.$message({
                showClose: true,
                message: '审核成功！',
                type: 'success'
              })
              let listQuery = {}
              this.getSpecialOperationList(listQuery)
              this.operationAuditCancel()
            })
          } else {
            return false
          }
        })
      }
    }
  }
</script>
<style type="text/css">
  a:link {text-decoration:none;color:blue;}
  a:hover {text-decoration:underline;color:red;}
  a:active{text-decoration:none;color:yellow;}
  a:visited {text-decoration:none;color:green;}
</style>
